﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NetDon.Utilities;

namespace NetDon.OA.Portal.Controls
{
    public partial class PageTaber : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var page = Page as PageBase;
            if (page != null)
            {
                var pageTabers = page.PageTabers;
                if (pageTabers != null && pageTabers.Count > 0)
                {
                    rptPagerTaber.DataSource = pageTabers;
                    rptPagerTaber.DataBind();
                    PageTab currentPager = null;
                    foreach (var pageTaber in pageTabers)
                    {
                        if (page.GetType().IsAssignableFrom(pageTaber.Type) || page.GetType().BaseType.IsAssignableFrom(pageTaber.Type))
                        {
                            currentPager = pageTaber;
                            break;
                        }
                    }
                    if (currentPager != null)
                    {
                        var i = 0;
                        foreach (var control in rptPagerTaber.Controls)
                        {
                            var repeaterItem = control as RepeaterItem;
                            if ((repeaterItem.ItemType != ListItemType.Item && repeaterItem.ItemType != ListItemType.AlternatingItem) &&
              repeaterItem.ItemType != ListItemType.SelectedItem) continue;
                            var pageLink = repeaterItem.FindControl("hyperLinkPageTaber") as HyperLink;

                            if (pageLink != null)
                            {
                                if (i == currentPager.Index)
                                {
                                    pageLink.CssClass = "selected";
                                }
                                else
                                {
                                    pageLink.CssClass = "";
                                }
                            }
                            i++;
                        }
                        return;
                    }
                }
            }
            Visible = false;
        }
    }
}